<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <link rel="stylesheet" href="../css/login.css"/>
    <script src="../js/jquery-3.4.1.js"></script>

</head>
<body>
<div class="login">
    <img class="imga" src="../img/one.jpg">
    <div class="title">
        后台管理
    </div>

    <div class="input_div">
        <input id="name" class="input" name="name" placeholder="请输入管理员账号">
    </div>

    <div class="input_div">
        <input id="password" type="password" class="input" name="password" placeholder="请输入管理员密码">
    </div>

    <div class="input_div">
        <button onclick="login()" type="button" class="button">登陆</button>
    </div>

    <div id="error" class="error"></div>
</div>
</body>
<script>
    function login(){
        const name = $("#name").val();
        const password = $("#password").val();
        const error = $("#error")
        if (name === '' || password === ''){
            error.show();
            error.text("请输入完整的账号密码");
            return false;
        }
        $.ajax({
            url:"login",
            type:"post",
            dataType:"json",
            data:{name:name,password:password},
            success : function(data) {
                if(data){
                    error.hide();
                    location.href = "main";
                }else {
                    error.show();
                    error.text("检查账号密码是否正确");
                    return false;
                }
            }
        })
        // if(name === '1' && password ==='2'){
        //     error.hide();
        //
        // }else {
        //     error.show();
        //     error.text("检查账号密码是否正确");
        //     return false;
        // }
    }
</script>
</html>